package com.example.ruralservicedigitalplatform.controller.villager;

import com.example.ruralservicedigitalplatform.comment.Result;
import com.example.ruralservicedigitalplatform.domain.dto.OrderSubmitDto;
import com.example.ruralservicedigitalplatform.domain.po.PageResult;
import com.example.ruralservicedigitalplatform.domain.vo.OrderSubmitVO;
import com.example.ruralservicedigitalplatform.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("villagerOrderController")
@RequestMapping("/villager/order")
@Tag(name = "订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     * @param orderSubmitDto
     * @return
     */
    @Operation(summary = "用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrderSubmitDto orderSubmitDto){
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(orderSubmitDto);
        return Result.success(orderSubmitVO);
    }


    /**
     * 历史订单查询
     * @param page
     * @param pageSize
     * @param orderStatus
     * @return
     */
    @GetMapping("/historyOrders")
    @Operation(summary = "历史订单查询")
    public Result<PageResult> page(int page, int pageSize, Integer orderStatus){
        PageResult pageResult = orderService.pageQueryUser(page,pageSize,orderStatus);
        return Result.success(pageResult);
    }
}
